package com.zxl.handle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class MmMessageHandler {

    @Resource
    private AmqpTemplate rabbitTemplate;

    //yml文件配置mq.msg.exchange=msg.exchange
    @Value("${mq.msg.exchange}")
    private String exchange;

    /**
     * @param routingKey 常量MQ_ORDER_ROUTING_KEY = "order.routing.key";
     * @param jsonMsg    jsonMsg 消息内容
     */
    public void send(String routingKey, String jsonMsg) {
        log.info("exchange:{}", this.exchange);
        log.info("routingKey:{}", routingKey);
        log.info("jsonMsg:{}", jsonMsg);
        this.rabbitTemplate.convertAndSend(this.exchange, routingKey, jsonMsg);
        log.info("MsgHandler和MQ通信结果1:{}", "----------come here over");
    }
}
